package com.wyh.lotterysystem.dao.mapper;

import com.wyh.lotterysystem.dao.dataobject.PrizeDo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PrizeMapper {
    /**
     * 天剑奖品信息
     */
    @Insert("insert into prize (name, image_url, price, description)" +
            " values (#{name}, #{imageUrl}, #{price}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insert(PrizeDo prizeDo);

    @Select("select count(*) from prize")
    Integer count();

    @Select("select * from prize order by id desc limit #{offset}, #{pageSize} ")
    List<PrizeDo> checkPagePrize(Integer offset, Integer pageSize);

    @Select("<script>" +
            " select id from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Integer> getPrizes(@Param("items") List<Integer> prizeIds);

    @Select("<script>" +
            " select * from prize" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<PrizeDo> batchSelect(@Param("items") List<Integer> prizeIds);

    @Select("select * from prize where id = #{prizeId}")
    PrizeDo select(@Param("prizeId") Integer prizeId);
}
